package cate.game.role.res.findback.impl;

import cate.common.table.d.GD;
import cate.common.table.d.GDFunc;
import cate.common.table.farm.tower.row.TowerMainRow;
import cate.common.table.findback.base.FindBackBaseRow;
import cate.game.res.MixRes;
import cate.game.role.farm.tower.Tower;
import cate.game.role.res.findback.po.RoleFindBackFuncPO;
import easy.java.dev.note.NoteClass;

@NoteClass("资源找回-缚灵之塔")
public class RoleFindBackMainTowerPO extends RoleFindBackFuncPO {
    @Override
    public int getFuncId() {
        return GDFunc.TOWER;
    }

    @Override
    public void calcFindBack(boolean skipDay) {
        FindBackBaseRow config = getConfig();
        if (config == null) {
            return;
        }
        Tower mainTower = role.getFarm().tower;
        if (!mainTower.isOpen()) {
            return;
        }
        if (mainTower.passedFloor <= 0) {
            return;
        }
        TowerMainRow tpl = role.getGame().table.tower.main.get(mainTower.passedFloor);
        if(tpl == null){
            return;
        }
        int findBackTimes = skipDay ?
                mainTower.mopTimes.getFreeTotal(role, getFuncId())
                : mainTower.mopTimes.getFreeRemain(role, getFuncId());
        if (findBackTimes > 0) {
            MixRes res = new MixRes(tpl.rewardStr);
            if (!res.isEmpty()) {
                this.times = findBackTimes;
                this.freeReward = res.copy().multiplyDouble(config.rate / GD.W_10000_0);
                this.cost = new MixRes(config.costStr);
                this.payReward = res.copy();
            }
        }
    }
}
